<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
	
class Output Extends CI_Controller
{
	public function __construct()
	{
		parent::__construct();
		$this->page_auth->secure_output_page();
		
	}
		
	function get_section_data($id,$auth='')
	{
		if($this->authlink->verify_authlink($auth) == FALSE OR !(int)$id)
		{
			echo 'Error 404';
		}else
		{
			$this->load->model(array('M_grade_level_sections'));
			$id = intval($id);
			$data = $this->M_grade_level_sections->get_section_by_level($id);
			$template = NULL;
			
			if(!empty($data))
			{	
				$template.= '<option value="choose_sections">Choose Sections</option>';
				foreach ($data as $data)
				{
					$template .= '<option value="'.$data->section_id.'">'.$data->section_name.'</option>';
				}
			}else
			{
				$template .= '<option value="no_sections">No Sections Assigned Yet</option>';
			}
			echo($template);
		}
	}
	
	function get_gradelevel_data($auth='', $grade_level='')
	{
		if($this->authlink->verify_authlink($auth))
		{
			$this->load->model('M_levels','ml');
			$data = $this->ml->get_all_levels_array_two();
			if($data)
			{
				$option = 'size="10" multiple';
				if($grade_level != ''){
					echo '
					<div>
						<label>Select Grade Level</label>
					'.
					form_dropdown('grade_level[]',$data,$grade_level,$option).'</div>';
				}else{
				echo '
				<div class="small-3 columns">
					<label>Select Grade Level</label>
				</div>
				<div class="small-9 columns">'.
				form_dropdown('grade_level[]',$data,'',$option).'</div>';
				}
			}else{
				echo '<div class="alert"><a class="btn btn-mini" href="'.site_url('admin/add_grade_level').'">No Grade Level Available</a></div>';
			}
		}else{
			echo 'NULL';
		}
	}
	
	function get_gradelevel_data_two($auth='', $grade_level='')
	{
		if($this->authlink->verify_authlink($auth))
		{
			$this->load->model('M_levels','ml');
			$data = $this->ml->get_all_levels_array();
			if($data)
			{
				if($grade_level != ''){
					echo '
					<div>
						<label>Select Grade Level</label>
					'.
					form_dropdown('grade_level',$data,$grade_level).'</div>';
				}else{
				echo '
				<div class="small-3 columns">
					<label>Select Grade Level</label>
				</div>
				<div class="small-9 columns">'.
				form_dropdown('grade_level',$data).'</div>';
				}
			}else{
				echo '<div class="alert"><a class="btn btn-mini" href="'.site_url('admin/add_grade_level').'">No Grade Level Available</a></div>';
			}
		}else{
			echo 'NULL';
		}
	}
	
	public function birthday_search($auth)
	{
		if($this->authlink->verify_authlink($auth))
		{
			$this->load->model('M_search','ms');
			$search_term = $this->input->post('s');	
			echo json_encode($this->ms->search_birthdays($search_term));
		}
	}
	
	public function ajax_check_assessment_fee()
	{
	  $student_id_no = $this->input->get('id');
	  
	  if($student_id_no)
	  {
		   $this->load->model('M_assessment_fees','maf');
		   $result = $this->maf->get_enrollment_id($student_id_no);
		   $result_af = $this->maf->get_assessment_fee($result->e_id);
		   
		   $template = '<script>$("#to_hide").css("display","none");</script>';
		   $template .='<a href="'.base_url().'pdf/assessment_fee/'.$result->e_id.'/YhfUNfdsakbd" target="_blank">Print New Student Assessment & Application FORM</a>';
		   if($result_af)
		   {
				echo $template;
		   }

	  }else{
	  
	  
	  }


	}
	
	public function ajax_search_student()
	{

		$x = $this->input->get('term', TRUE);
		$this->load->model('M_search','ms');
		
		$result = $this->ms->search_student_like($x);
		
		if($result == FALSE)
		{
			$data[] = array('value'=>'value','label'=>'No Student Found','id'=>'id');
		}else{
			$data = $result;
		}
		

		$this->output
			 ->set_content_type('application/json')
			 ->set_output(json_encode($data));
	}
	
	public function finance_search_student()
	{
		$x = $this->input->get('term', TRUE);
		$this->load->model('M_search','ms');
		
		$result = $this->ms->search_student_like_registrar_verified($x);
		
		if($result == FALSE)
		{
			$data[] = array('value'=>'value','label'=>'No Student Found','id'=>'id');
		}else{
			$data = $result;
		}
		
		// echo $data;

		$this->output
			 ->set_content_type('application/json')
			 ->set_output(json_encode($data));
	}
	
	public function payment_plan($grade_level)
	{
		echo'
		<table class="table table-striped table-hover">
		<thead>
			<tr>
				<td>Month</td>
				<td colspan="2" class="text-center text-info">&nbsp;</td>
			</tr>
			<tr>
				<td>&nbsp;</td>
				<td>NEW</td>
				<td>OLD</td>
			</tr>
		</thead>
		<tbody>
			<tr>
				<td><strong>TOTAL</strong></td>
				<td><input id="total-old"  type="text" value=""  disabled></td>
				<td><input id="total-new"  type="text" value=""   disabled></td>
			</tr>
			<tr>
				<td>January</td>
				<td><input name="old_'.$grade_level.'_jan" type="text" value="'.set_value('old_'.$grade_level.'_jan',${'old_'.$grade_level.'_jan'}).'"></td>
				<td><input name="new_'.$grade_level.'_jan" type="text" value="'.set_value('new_'.$grade_level.'_jan',${'new_'.$grade_level.'_jan'}).'"></td>
			</tr>
			';/*
			<tr>
				<td>Febuary</td>
				<td><input class="table-input annual" name="annual_<?=$data;?>_feb" type="text" value="<?=set_value('annual_'.$data.'_feb',${'annual_'.$data.'_feb'});?>"></td>
				<td><input class="table-input semestral" name="semestral_<?=$data;?>_feb" type="text" value="<?=set_value('semestral_'.$data.'_feb',${'semestral_'.$data.'_feb'});?>"></td>
				<td><input class="table-input trimester"name="trimester_<?=$data;?>_feb" type="text" value="<?=set_value('trimester_'.$data.'_feb',${'trimester_'.$data.'_feb'});?>"></td>
				<td><input class="table-input monthly" name="monthly_<?=$data;?>_feb" type="text" value="<?=set_value('monthly_'.$data.'_feb',${'monthly_'.$data.'_feb'});?>"></td>
			</tr>
			<tr>
				<td>March</td>
				<td><input class="table-input2 annual" name="annual_<?=$data;?>_mar" type="text" value="<?=set_value('annual_'.$data.'_mar',${'annual_'.$data.'_mar'});?>"></td>
				<td><input class="table-input2 semestral" name="semestral_<?=$data;?>_mar" type="text" value="<?=set_value('semestral_'.$data.'_mar',${'semestral_'.$data.'_mar'});?>"></td>
				<td><input class="table-input2 trimester" name="trimester_<?=$data;?>_mar" type="text" value="<?=set_value('trimester_'.$data.'_mar',${'trimester_'.$data.'_mar'});?>"></td>
				<td><input class="table-input2 monthly" name="monthly_<?=$data;?>_mar" type="text" value="<?=set_value('monthly_'.$data.'_mar',${'monthly_'.$data.'_mar'});?>"></td>
			</tr>
			<tr>
				<td>April</td>
				<td><input class="table-input annual" name="annual_<?=$data;?>_apr" type="text" value="<?=set_value('annual_'.$data.'_apr',${'annual_'.$data.'_apr'});?>"></td>
				<td><input class="table-input semestral" name="semestral_<?=$data;?>_apr" type="text" value="<?=set_value('semestral_'.$data.'_apr',${'semestral_'.$data.'_apr'});?>"></td>
				<td><input class="table-input trimester" name="trimester_<?=$data;?>_apr" type="text" value="<?=set_value('trimester_'.$data.'_apr',${'trimester_'.$data.'_apr'});?>"></td>
				<td><input class="table-input monthly" name="monthly_<?=$data;?>_apr" type="text" value="<?=set_value('monthly_'.$data.'_apr',${'monthly_'.$data.'_apr'});?>"></td>
			</tr>
			<tr>
				<td>May</td>
				<td><input class="table-input2 annual" name="annual_<?=$data;?>_may" type="text" value="<?=set_value('annual_'.$data.'_may',${'annual_'.$data.'_may'});?>"></td>
				<td><input class="table-input2 semestral" name="semestral_<?=$data;?>_may" type="text" value="<?=set_value('semestral_'.$data.'_may',${'semestral_'.$data.'_may'});?>"></td>
				<td><input class="table-input2 trimester" name="trimester_<?=$data;?>_may" type="text" value="<?=set_value('trimester_'.$data.'_may',${'trimester_'.$data.'_may'});?>"></td>
				<td><input class="table-input2 monthly" name="monthly_<?=$data;?>_may" type="text" value="<?=set_value('monthly_'.$data.'_may',${'monthly_'.$data.'_may'});?>"></td>
			</tr>
			<tr>
				<td>June</td>
				<td><input class="table-input annual" name="annual_<?=$data;?>_jun" type="text" value="<?=set_value('annual_'.$data.'_jun',${'annual_'.$data.'_jun'});?>"></td>
				<td><input class="table-input semestral" name="semestral_<?=$data;?>_jun" type="text" value="<?=set_value('semestral_'.$data.'_jun',${'semestral_'.$data.'_jun'});?>"></td>
				<td><input class="table-input trimester" name="trimester_<?=$data;?>_jun" type="text" value="<?=set_value('trimester_'.$data.'_jun',${'trimester_'.$data.'_jun'});?>"></td>
				<td><input class="table-input monthly" name="monthly_<?=$data;?>_jun" type="text" value="<?=set_value('monthly_'.$data.'_jun',${'monthly_'.$data.'_jun'});?>"></td>
			</tr>
			<tr>
				<td>July</td>
				<td><input class="table-input2 annual" name="annual_<?=$data;?>_jul" type="text" value="<?=set_value('annual_'.$data.'_jul',${'annual_'.$data.'_jul'});?>"></td>
				<td><input class="table-input2 semestral" name="semestral_<?=$data;?>_jul" type="text" value="<?=set_value('semestral_'.$data.'_jul',${'semestral_'.$data.'_jul'});?>"></td>
				<td><input class="table-input2 trimester"name="trimester_<?=$data;?>_jul" type="text" value="<?=set_value('trimester_'.$data.'_jul',${'trimester_'.$data.'_jul'});?>"></td>
				<td><input class="table-input2 monthly" name="monthly_<?=$data;?>_jul" type="text" value="<?=set_value('monthly_'.$data.'_jul',${'monthly_'.$data.'_jul'});?>"></td>
			</tr>
			<tr>
				<td>August</td>
				<td><input class="table-input annual" name="annual_<?=$data;?>_aug" type="text" value="<?=set_value('annual_'.$data.'_aug',${'annual_'.$data.'_aug'});?>"></td>
				<td><input class="table-input semestral" name="semestral_<?=$data;?>_aug" type="text" value="<?=set_value('semestral_'.$data.'_aug',${'semestral_'.$data.'_aug'});?>"></td>
				<td><input class="table-input trimester"name="trimester_<?=$data;?>_aug" type="text" value="<?=set_value('trimester_'.$data.'_aug',${'trimester_'.$data.'_aug'});?>"></td>
				<td><input class="table-input monthly" name="monthly_<?=$data;?>_aug" type="text" value="<?=set_value('monthly_'.$data.'_aug',${'monthly_'.$data.'_aug'});?>"></td>
			</tr>
			<tr>
				<td>September</td>
				<td><input class="table-input2 annual" name="annual_<?=$data;?>_sep" type="text" value="<?=set_value('annual_<'.$data.'_sep',${'annual_'.$data.'_sep'});?>"></td>
				<td><input class="table-input2 semestral" name="semestral_<?=$data;?>_sep" type="text" value="<?=set_value('semestral_'.$data.'_sep',${'semestral_'.$data.'_sep'});?>"></td>
				<td><input class="table-input2 trimester"name="trimester_<?=$data;?>_sep" type="text" value="<?=set_value('trimester_'.$data.'_sep',${'trimester_'.$data.'_sep'});?>"></td>
				<td><input class="table-input2 monthly" name="monthly_<?=$data;?>_sep" type="text" value="<?=set_value('monthly_'.$data.'_sep',${'monthly_'.$data.'_sep'});?>"></td>
			</tr>
			<tr>
				<td>October</td>
				<td><input class="table-input annual" name="annual_<?=$data;?>_oct" type="text" value="<?=set_value('annual_'.$data.'_oct',${'annual_'.$data.'_oct'});?>"></td>
				<td><input class="table-input semestral" name="semestral_<?=$data;?>_oct" type="text" value="<?=set_value('semestral_'.$data.'_oct',${'semestral_'.$data.'_oct'});?>"></td>
				<td><input class="table-input trimester"name="trimester_<?=$data;?>_oct" type="text" value="<?=set_value('trimester_'.$data.'_oct',${'trimester_'.$data.'_oct'});?>"></td>
				<td><input class="table-input monthly" name="monthly_<?=$data;?>_oct" type="text" value="<?=set_value('monthly_'.$data.'_oct',${'monthly_'.$data.'_oct'});?>"></td>
			</tr>
			<tr>
				<td>November</td>
				<td><input class="table-input2 annual" name="annual_<?=$data;?>_nov" type="text" value="<?=set_value('annual_'.$data.'_nov',${'annual_'.$data.'_nov'});?>"></td>
				<td><input class="table-input2 semestral" name="semestral_<?=$data;?>_nov" type="text" value="<?=set_value('semestral_'.$data.'_nov',${'semestral_'.$data.'_nov'});?>"></td>
				<td><input class="table-input2 trimester"name="trimester_<?=$data;?>_nov" type="text" value="<?=set_value('trimester_<'.$data.'_nov',${'trimester_'.$data.'_nov'});?>"></td>
				<td><input class="table-input2 monthly"  name="monthly_<?=$data;?>_nov" type="text" value="<?=set_value('monthly_'.$data.'_nov',${'monthly_'.$data.'_nov'});?>"></td>
			</tr>
			<tr>
				<td><strong>TOTAL</strong></td>
				<td><input id="total-annual"  type="text" value=""  disabled></td>
				<td><input id="total-semestral"  type="text" value=""   disabled></td>
				<td><input id="total-trimester" type="text" value=""   disabled></td>
				<td><input id="total-monthly" type="text" value=""   disabled></td>
			</tr>
			<tr>
				<td  colspan="5">
					<input type="hidden" name="spl_loc" value="<?=$form_token;?>">
					<input type="hidden" name="type" value="<?=$data;?>">
					<input type="hidden" name="id" value="<?=$data;?>">
					<input type="submit" name="payment_mode" class="btn btn-primary" value="Save Payment Plan">
				</td>
			</tr>
			<tr>
				<td>Registration</td>
				<td><input class="table-input annual" name="old_<?=$data;?>_dec" type="text" value="<?=set_value('annual_'.$data.'_dec',${'annual_'.$data.'_dec'});?>"></td>
				<td><input class="table-input semestral" name="semestral_<?=$data;?>_dec" type="text" value="<?=set_value('semestral_'.$data.'_dec',${'semestral_'.$data.'_dec'});?>"></td>
				<td><input class="table-input trimester"name="trimester_<?=$data;?>_dec" type="text" value="<?=set_value('trimester_'.$data.'_dec',${'trimester_'.$data.'_dec'});?>"></td>
				<td><input class="table-input monthly" name="monthly_<?=$data;?>_dec" type="text" value="<?=set_value('monthly_'.$data.'_dec',${'monthly_'.$data.'_dec'});?>"></td>
			</tr>
		</tbody>
		</table>
		';*/
	}
	
	public function set_schedule($schedule,$section)
	{
		$post = $this->input->post();

		if($post)
		{
			$this->load->model('M_schedule','msched');
			$result = $this->msched->for_ajax_update_sched($post,$schedule,$section);
		}else{
			$result = 0;
		}
		sleep(2);
		$this->output
			 ->set_content_type('application/json')
			 ->set_output(json_encode($result));
	}
	
	public function ajax_search_employees()
	{
		$x = $this->input->get('term', TRUE);
		$this->load->model('M_employees','memp');
		
		$result = $this->memp->ajax_search_employees(TRUE,$x);
		
		if($result == FALSE)
		{
			$data[] = array('value'=>'value','label'=>'No employee found.','id'=>'id');
		}else{
			$data = $result;
		}

		$this->output
			 ->set_content_type('application/json')
			 ->set_output(json_encode($data));
	}

	public function si()
	{
		$this->load->model('M_search','ms');
		
		$data['total'] = $this->ms->count_inquiries();
		echo json_encode($data);
	}
	
	public function sa()
	{
		$this->load->model('M_search','ms');
		
		$data['total'] = $this->ms->count_applicants();
		echo json_encode($data);
	}
	
	public function se()
	{
		$this->load->model('M_search','ms');
		
		$data['total'] = $this->ms->count_approved_enrollees();
		echo json_encode($data);
	}
	
	public function sra()
	{
		$this->load->model('M_search','ms');
		
		$data['total'] = $this->ms->count_registrar_approved();
		echo json_encode($data);
	}

	public function soe()
	{
		$this->load->model('M_search','ms');
		
		$data['total'] = $this->ms->count_approved_enrolled();
		echo json_encode($data);
	}
	
	public function ajax_search_inquiry()
	{
		$x = $this->input->get('term', TRUE);
		$this->load->model('M_search','ms');
		
		$result = $this->ms->search_inquiries(TRUE,$x);
		
		if($result == FALSE)
		{
			$data[] = array('value'=>'value','label'=>'No Inquiry Found','id'=>'id');
		}else{
			$data = $result;
		}
		
		// echo $data;

		$this->output
			 ->set_content_type('application/json')
			 ->set_output(json_encode($data));
	}
	
	public function ajax_search_applicants()
	{
		$x = $this->input->get('term', TRUE);
		$this->load->model('M_search','ms');
		
		$result = $this->ms->search_applicants(TRUE,$x);
		
		if($result == FALSE)
		{
			$data[] = array('value'=>'value','label'=>'No Applicant Found','id'=>'id');
		}else{
			$data = $result;
		}
		
		// echo $data;

		$this->output
			 ->set_content_type('application/json')
			 ->set_output(json_encode($data));
	}
	
	public function ajax_search_enrollee()
	{
		$x = $this->input->get('term', TRUE);
		$this->load->model('M_search','ms');
		
		$result = $this->ms->search_approved_enrollees(TRUE,$x);
		
		if($result == FALSE)
		{
			$data[] = array('value'=>'value','label'=>'No Enrollee Found','id'=>'id');
		}else{
			$data = $result;
		}
		
		// echo $data;

		$this->output
			 ->set_content_type('application/json')
			 ->set_output(json_encode($data));
	}
	
	public function ajax_search_registrar_approved()
	{
		$x = $this->input->get('term', TRUE);
		$this->load->model('M_search','ms');
		
		$result = $this->ms->search_registrar_approved(TRUE,$x);
		
		if($result == FALSE)
		{
			$data[] = array('value'=>'value','label'=>'No Registrar Approved Enrollee Found','id'=>'id');
		}else{
			$data = $result;
		}
		
		// echo $data;

		$this->output
			 ->set_content_type('application/json')
			 ->set_output(json_encode($data));
	}
	
	public function ajax_search_officially_enrolled()
	{
		$x = $this->input->get('term', TRUE);
		$this->load->model('M_search','ms');
		
		$result = $this->ms->search_approved_enrolled(TRUE,$x);
		
		if($result == FALSE)
		{
			$data[] = array('value'=>'value','label'=>'No Officially Enrolled Found','id'=>'id');
		}else{
			$data = $result;
		}
		
		// echo $data;

		$this->output
			 ->set_content_type('application/json')
			 ->set_output(json_encode($data));
	}
	
	public function set_student_grades($hash)
	{
		$x = $this->hs->decrypt($hash);
		$post = $this->input->post();
		
		// pd($post);
		if($post && $x)
		{
			
			sleep(1);
			$this->load->model('M_teachers','mteach');
			$rs = $this->mteach->update_student_grade($post,$x[0]);
			$result = $rs?1:0;
		}else{
			$result = 0;
		}
		
		$this->output
			 ->set_content_type('application/json')
			 ->set_output(json_encode($result));	
	
	}
	
	public function del_student_grades($hash)
	{
		$x = $this->hs->decrypt($hash);
				
		// pd($x);
		if($x)
		{
			
			sleep(1);
			$this->load->model('M_teachers','mteach');
			$this->mteach->del_student_grade($x[0],$x[1]);
			$result = 1;
		}else{
			$result = 0;
		}
		
		$this->output
			 ->set_content_type('application/json')
			 ->set_output(json_encode($result));
	}
	
	public function advisory_remarks($hash = '')
	{
		$x = $this->hs->decrypt($hash);
		$post = $this->input->post();
		if($x)
		{
			sleep(2);
			$this->load->model('M_teachers','mt');
			$result = $this->mt->add_student_remarks($x[0],$post);
		}else{
			$result = false;
		}
	
		$this->output
			 ->set_content_type('application/json')
			 ->set_output(json_encode($result));
	}
	
	public function updatecurriculumorder($hash='')
	{
		$x = $this->hs->decrypt($hash);
		if($this->input->post() && $x)
		{
			$option = intval($this->input->post('option'));

			$this->load->model('M_curriculum');
			$res = $this->M_curriculum->set_order($option,$x[0]);

			header('Content-Type: application/json');
			echo json_encode($res);
			exit();
		}
	}
	
	public function fetch_events($event_id = '00000')
	{
		$this->load->model('M_calendar','mcal');
		$result = $this->mcal->get_event($event_id);
		$html = '';
		if($result)
		{
			$from = new DateTime($result->event_start);
			$end = new DateTime($result->event_end);
			$end->modify('-1 Day');
			$diff = $from->diff($end);
			$html.= '<div>';
				$html.= '<label class="label">Name of Event</label>';
				$html.= '<p>'.htmlentities($result->event_name).'</p>';
			$html.= '</div>';
			$html.= '<hr>';

			$html.= '<div>';
				$html.= '<div style="width:33%;display:inline-block;">';
					$html.= '<label class="label">Start Date</label>';
					$html.= '<p>'.$from->format('M d, Y').'</p>';
				$html.= '</div>';
				$html.= '<div style="width:33%;display:inline-block;">';
					$html.= '<label class="label">End Date</label>';
					$html.= '<p>'.$end->format('M d, Y').'</p>';
				$html.= '</div>';
				$html.= '<div style="width:33%;display:inline-block;">';
					$html.= '<label class="label">Days</label>';
					$html.= '<p>'.intval($diff->days + 1).'Days</p>';
				$html.= '</div>';
			$html.= '</div>';
			$html.= '<hr>';
			$html.= '<div>';
				$html.= '<label class="label">Description</label>';
				$html.= '<p>'.htmlentities($result->event_desc).'</p>';
			$html.= '</div>';
			$html.= '<hr>';
			$html.= '<div>';
				$html.= '<div style="width:49%;display:inline-block;">';
					$html.= '<label class="label">Posted By</label>';
					$html.= '<p>'.$result->event_created_by.'</p>';
				$html.= '</div>';
				$html.= '<div style="width:49%;display:inline-block;">';
					$html.= '<label class="label">Posted On</label>';
					$html.= '<p>'.$result->created.'</p>';
				$html.= '</div>';
			$html.= '</div>';
			$html.= '<a href="'.site_url('output/deleteevent/'.$event_id).'" data-batchid="'.$event_id.'" class="btn btn-warning delete-event confirm">Delete This Event</a>';
			$html.= '<a href="'.site_url('calendar/editevent/'.$event_id).'" class="btn btn-success">Edit This Event</a>';
		}else{
			$html .= '<div class="alert-box">Unable to get events.</div>';
		}
		echo $html;
	}

	public function deleteevent($event_id)
	{
		if(IS_AJAX)
		{
			$this->load->model('M_calendar','mcal');
			$result = $this->mcal->delete_event($event_id);

			if($result){
				$res =1;
			}else{
				$res =0;
			}

			header('Content-Type: application/json');
			echo json_encode($res);
			exit();
		}
	}
	
	public function get_students_for_parent_login()
	{
		if(IS_AJAX)
		{
			$post = $this->input->post('studentname');
			$this->load->model('M_search');
			$result = $this->M_search->get_students_for_parent_login($post);
			header('Content-Type: application/json');
			echo json_encode($result);
			exit();
		}
	}
	
	public function advisory_attendance($column = FALSE,$hash)
	{
		$x = $this->hs->decrypt($hash);

		if(IS_AJAX && $x)
		{
			$post = $this->input->post();
			
			$this->load->model('M_student_attendance','msatt');
			$result = $this->msatt->set_student_attendance($column,$x[0],$post);
			header('Content-Type: application/json');
			echo json_encode($result);
			exit();
		}
	}
	
	public function updatelearningareas($hash = '')
	{
		$x = $this->hs->decrypt($hash);

		if(IS_AJAX && $x)
		{
			$id = $x[0];
			$option = $this->input->post('option');
			$this->load->model('M_curriculum','mcur');
			$result = $this->mcur->update_learning_areas($id,$option);
			header('Content-Type: application/json');
			echo json_encode($result);
			exit();
		}	
	}
	
	public function assignstudentsection($id = FALS)
	{
		$x = $this->hs->decrypt($id);
	
		if($x && $this->input->post())
		{
			$option = $this->input->post('option');
			$e_id = $x[0];
			$l_id = $x[1];
			
			
			// pp('enrollment Id: '.$e_id);
			// pp('Level Id: '.$l_id);
			// pd($option);

			$this->load->model(['M_enrollees','M_student_subjects','M_student_grades','M_student_attendance']);	 
		
			$response = $this->M_enrollees->assign_student_section($e_id, $option);

			if($response == 'SUCCESS')
			{
				$this->M_student_subjects->generate_student_subjects($e_id, $l_id);
				$this->M_student_grades->generate_student_grades($e_id, $option);
				$this->M_student_grades->generate_remarks($e_id);
				$this->M_student_attendance->generatestudentattendance($e_id);
				$this->M_student_subjects->generate_student_subject_children($e_id, $l_id,$option);

				$res = 1;
			}else{
				$res = 0;
			}
		}else{
			$res = 1;		
		}

		$this->output->set_content_type('application/json')
			 ->set_output(json_encode($res));
	}
	
	public function returall_subjectparent()
	{
		$term = htmlentities(strip_tags($this->input->get('term')));
		$this->load->model('M_subjects');
		$result = $this->M_subjects->get_all_parent_subjects($term);

		$this->output
			 ->set_content_type('application/json')
			 ->set_output(json_encode($result));
	}
	
	public function commendation($hash = '')
	{
		$x = $this->hs->decrypt($hash);

		if(IS_AJAX && $x)
		{
			$id = $x[0];
			$option = $this->input->post();
			$this->load->model('M_teachers','mteach');
			
			$result = $this->mteach->send_commendations($id,$option);

			header('Content-Type: application/json');
			echo json_encode($result);
			exit();
		}
	}
	
	public function ajax_get_items()
	{
		$x = $this->input->get('term',TRUE);
		$this->load->model('M_custodian','mc');
		$res = $this->mc->get_items_where($x);
		
		$this->output
			 ->set_content_type('application/json')
			 ->set_output(json_encode($res));
	}
}